<template>
  <div class="m_contentBox">
    <a-card :bordered="false">
      <div class="m_aCardBox">
        <!-- 查询区域 -->
        <div class="tabBox">
          <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery" class="flex-space-between-wrapper">
              <div>
                <a-row :gutter="24">
                  <a-col :span="6">
                    <a-form-item label="">
                      <a-input placeholder="用户名" v-model="queryParam.realname"></a-input>
                    </a-form-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-item label="">
                      <a-input placeholder="用户账户" v-model="queryParam.username"></a-input>
                    </a-form-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-item label="">
                      <j-search-select-tag placeholder="所属企业" v-model="queryParam.organizationId"
                                           dict="cy_platform_organization_info,name,id,del_flag = '0'" :async="true">
                      </j-search-select-tag>
                    </a-form-item>
                  </a-col>
                  <a-col :span="6">
                    <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                      <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                      <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                    </span>
                  </a-col>
                </a-row>
              </div>
              <!-- 操作按钮区域 -->
              <div class="table-operator">
                <a-button @click="handleAdd" type="primary" icon="link">绑定</a-button>
                <a-button @click="handleAddUser" type="primary" icon="plus">新增</a-button>
              </div>
            </a-form>
          </div>
        </div>
        <!-- 查询区域-END -->
        <!-- table区域-begin -->
        <div class="cardBox">
          <a-table ref="table" size="middle" :scroll="{ x: true }" :columns="columns" :dataSource="dataSource"
                   :pagination="ipagination" :loading="loading" class="j-table-force-nowrap"
                   @change="handleTableChange">
            <span slot="defaultBind" slot-scope="text,record" v-if="record.id">
              <a-switch :checked="text" @change="handleDefaultBindChange($event, record)"/>
            </span>
            <span slot="action" slot-scope="text, record">
              <a-popconfirm title="确定解绑吗?" @confirm="() => handleDelete(record.id)" v-if="record.id">
                <a :disabled="false">解绑</a>
              </a-popconfirm>
              <a @click="handleEdit({userId: record.userId})" v-else :disabled="false">绑定</a>
            </span>
          </a-table>
        </div>

        <member-info-modal ref="modalForm" @ok="modalFormOk"></member-info-modal>
        <user-modal ref="userModalForm" @ok="modalFormOk"></user-modal>
      </div>
    </a-card>
  </div>
</template>

<script>

import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import MemberInfoModal from './modules/MemberInfoModal.Style#Drawer.vue'
import {filterDictTextByCache} from '@/components/dict/JDictSelectUtil';
import {getAction} from '@/api/manage'
import UserModal from '@/views/system/modules/UserModal'

export default {
  name: 'memberList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    MemberInfoModal, UserModal
  },
  data() {
    return {
      description: '平台组织管理管理页面',
      // 表头
      columns: [
        {
          title: '用户名',
          align: "center",
          dataIndex: 'realname'
        },
        {
          title: '用户账号',
          align: "center",
          dataIndex: 'username'
        },
        {
          title: '所属企业',
          align: "center",
          dataIndex: 'name'
        },
        {
          title: '组织类型',
          align: "center",
          dataIndex: 'type',
          customRender: (text, record, index) => {
            //字典值替换通用方法
            return filterDictTextByCache('organization_type', text);
          }
        },
        {
          title: '邮箱',
          align: "center",
          dataIndex: 'email'
        },
        {
          title: "注册时间",
          align: "center",
          dataIndex: 'registerTime'
        },
        // {
        //   title: '管理员',
        //   align: "center",
        //   dataIndex: 'defaultBind',
        //   scopedSlots: { customRender: 'defaultBind' }
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        list: "/platform/cyPlatformOrganizationAndMember/list",
        delete: "/platform/cyPlatformOrganizationAndMember/delete",
        switch: "/platform/cyPlatformOrganizationAndMember/switch",
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    handleDefaultBindChange(checked, record) {
      record.defaultBind = checked
      getAction(this.url.switch, {id: record.id, bind: checked}).then((res) => {
        if (res.success) {
          this.$message.success("操作成功");
        } else {
          this.$message.error(res.message);
          record.defaultBind = !checked
        }
      })
    },
    handleAddUser() {
      this.$refs.userModalForm.title = '新增'
      this.$refs.userModalForm.orgAdd()
    },
  }
}
</script>
<style lang="less" scoped>

/deep/ .ant-card-body {
  background: #F5F8F7;
}

.tabBox {
  padding: 24px 24px 0;
  background: #FFFFFF;
  border-radius: 3px;
}

.cardBox {
  margin-top: 24px;
  padding: 24px;
  background: #FFFFFF;
  border-radius: 3px;
}
</style>